﻿// <copyright file="TraitsGM.cs" company="Gravity Age Studios">
// Code released under the MIT license (see License.txt).
// </copyright>
// <author>Vicente Cartas Espinel</author>
// <email>vicente.cartas@gmail.com</email>
namespace LightSwitchApplication
{
    using LightSwitchApplication.UserCode;
    using Microsoft.LightSwitch.Presentation.Extensions;

    public partial class TraitsGM
    {
        #region Add/Edit Trait

        partial void gridAddAndEditNew_Execute()
        {
            var trait = this.Collection.AddNew();
            trait.Visibility = (int)VisibilityEnum.Public;

            this.FindControl("ModalWindow").DisplayName = "Add Trait";
            this.OpenModalWindow("ModalWindow");
        }

        partial void gridEditSelected_CanExecute(ref bool result)
        {
            result = this.Collection.SelectedItem != null;
        }

        partial void gridEditSelected_Execute()
        {
            this.FindControl("ModalWindow").DisplayName = "Edit Trait";
            this.OpenModalWindow("ModalWindow");
        }

        partial void SubmitModalWindow_Execute()
        {
            this.CloseModalWindow("ModalWindow");
        }

        partial void CancelModalWindow_Execute()
        {
            this.CloseModalWindow("ModalWindow");
            this.Collection.SelectedItem.Details.DiscardChanges();
        }

        #endregion

        #region Add New/Edit Modifier

        partial void RelationTraitModifiersAddNew_Execute()
        {
            var relation = this.RelationTraitModifiers.AddNew();
            relation.Modifier = new Modifier();
            this.NewModifier = relation.Modifier;

            this.FindControl("ModalNewModifier").DisplayName = "Add new Modifier";
            this.OpenModalWindow("ModalNewModifier");
        }

        partial void RelationTraitModifiersEditSelected_CanExecute(ref bool result)
        {
            result = this.RelationTraitModifiers.SelectedItem != null;
        }

        partial void RelationTraitModifiersEditSelected_Execute()
        {
            this.NewModifier = this.RelationTraitModifiers.SelectedItem.Modifier;

            this.FindControl("ModalNewModifier").DisplayName = "Edit Modifier";
            this.OpenModalWindow("ModalNewModifier");
        }

        partial void SubmitModalNew_Execute()
        {
            this.CloseModalWindow("ModalNewModifier");
        }

        partial void CancelModalNew_Execute()
        {
            this.CloseModalWindow("ModalNewModifier");
            this.RelationTraitModifiers.SelectedItem.Details.DiscardChanges();
        }

        #endregion

        partial void Import_Execute()
        {
        }
    }
}
